//
//  PayListViewController.m
//  SEGWebView
//
//  Created by 山刘 on 2020/3/12.
//

#import "PayListViewController.h"
#import "PayResultViewController.h"

@interface PayListViewController ()
@property (nonatomic, strong)UIButton *paySuccessButton;
@end

@implementation PayListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    self.title = @"支付列表";
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getOrderPayResult:) name:@"ORDER_PAY_NOTIFICATION" object:nil];
    
    _paySuccessButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_paySuccessButton addTarget:self action:@selector(confirmClick) forControlEvents:UIControlEventTouchUpInside];
    [_paySuccessButton setTitle:@"发起支付" forState:UIControlStateNormal];
    [_paySuccessButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_paySuccessButton setBackgroundColor:[UIColor redColor]];
    [_paySuccessButton sizeToFit];
    _paySuccessButton.frame = CGRectMake(15,100, [UIScreen mainScreen].bounds.size.width-30, CGRectGetHeight(_paySuccessButton.bounds));
    _paySuccessButton.layer.masksToBounds = YES;
    _paySuccessButton.layer.cornerRadius = 5;
    [self.view addSubview:_paySuccessButton];
}

-(void)confirmClick{
    NSURL *url = [NSURL URLWithString:@"app2Scheme://"];
    if (![[UIApplication sharedApplication] canOpenURL:url]){
        NSLog(@"没有安装应用SchemesA");
        return;
    }
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
    }];
}

- (void)getOrderPayResult:(NSNotification*)notification
{
    NSLog(@"%@",notification.object);
    if ([notification.object isEqualToString:@"success"]) {
//        PayResultViewController *result = [PayResultViewController new];
//        result.hidesBottomBarWhenPushed = YES;
//        [self.navigationController pushViewController:result animated:YES];
        
        [self.navigationController popViewControllerAnimated:YES];
    }
    if ([notification.object isEqualToString:@"fail"]) {}
    if ([notification.object isEqualToString:@"cancel"]) {
//        if (self.payType == SEGPayTypeName_CMHK_PayOnLine) {
//            //self.linkURL = qch_backUrl;
//            qch_backUrl = [SEGWebViewLoadManager segReplaceUrlStringWithUrlString:qch_backUrl];
//            [self refreshURL:qch_backUrl];
//        }
    }
}
@end
